package com.ssyan;

/**
 * @author ssyan
 * @Description 类的加载过程中初始化
 * @create 2021/8/15 23:49
 * @Version 1.0
 */
public class ClassInitTest {
    private static int num = 1;

    static {
        num = 2;
        number = 20;
        System.out.println(num);
        //System.out.println(number);//报错：非法的前向引用。
    }

    //可以先赋值静态变量值，再声明静态变量
    //linking prepare阶段已经对 number = 0
    //initial阶段：20 --> 10
    private static int number = 10;

    public static void main(String[] args) {
        System.out.println(ClassInitTest.num);
        System.out.println(ClassInitTest.number);
    }

}
